<% layout( 'admin_layout') -%>

    <script src="/js/fileinput.min.js" type="text/javascript"></script>
    <link href="/css/fileinput.css" media="all" rel="stylesheet" type="text/css" />
    <div id="wrapper" class="wrapper"></div>
    <div class="container-fulid">
        <%if(user.coverplan != ''){%>
            <header class="main-header no-cover" id="coverplan" data-toggle="modal" data-target="#cmyModal" style="background-image:url('<%=user.coverplan%>')">
                <%}else{%>
                    <header class="main-header no-cover" id="coverplan" data-toggle="modal" data-target="#cmyModal">
                        <%}%>

                            <div class="vertical">
                                <div class="main-header-content inner">
                                    <h1 class="page-title"><%=user.nickname%></h1>
                                    <h2 class="page-description"><%=user.description%></h2>
                                </div>
                            </div>

                    </header>
                    <!-- 模态框（Modal） -->

                    <div class="modal fade" id="cmyModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

                        <div class="modal-dialog">

                            <div class="modal-content">

                                <div class="modal-header">

                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

                                    <h4 class="modal-title" id="myModalLabel">

					请输入封面背景图片地址

					</h4>

                                </div>

                                <div class="modal-body">

                                    <input id="coverplanin" type="text" class="form-control" placeholder="http://">
                                    <!--this is a upload file test!-->
                                    <div>
                                        <form enctype="multipart/form-data">

                                            <label>Coverplan Input</label>
                                            <input id="file-coverplan" name="coverplan" type="file" multiple>
                                        </form>
                                    </div>
                                    <!--end test-->
                                </div>

                                <div class="modal-footer" style="margin-top:0;">

                                    <button id="ccacel" type="button" class="btn btn-default" data-dismiss="modal">取消</button>

                                    <button type="button" class="btn btn-primary" onclick="modifycoverplan()">提交更改</button>

                                </div>

                            </div>
                            <!-- /.modal-content -->

                        </div>
                        <!-- /.modal -->

                    </div>

                    <section class="content-wrap">

                        <div class="container">

                            <div class="raw" id="bodycontent">

                                <main id="content" class="main-content" role="main">

                                    <div class="col-sm-12 usname">

                                        <form class="form-horizontal" role="form">

                                            <div class="form-group">
                                                <%if(user.avatar == ''){%>

                                                    <img id="avatar" src="/img/timg.jpg" class="img-circle" alt="Cinque Terre" width="150" height="150" style="float:left;" data-toggle="modal" data-target="#myModal">

                                                    <%}else{%>
                                                        <img id="avatar" src="<%=user.avatar%>" class="img-circle" alt="Cinque Terre" width="150" height="150" style="float:left;" data-toggle="modal" data-target="#myModal">
                                                        <%}%>

                                                            <!-- 模态框（Modal） -->

                                                            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

                                                                <div class="modal-dialog">

                                                                    <div class="modal-content">

                                                                        <div class="modal-header">

                                                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

                                                                            <h4 class="modal-title" id="myModalLabel">

													请输入头像地址

												</h4>

                                                                        </div>

                                                                        <div class="modal-body">

                                                                            <input id="avatarin" type="text" class="form-control" placeholder="http://">
                                                                            <!--this is a upload file test!-->
                                                                            <div>
                                                                                <form enctype="multipart/form-data">

                                                                                    <label>Avatar Input</label>
                                                                                    <input id="file-avatar" name="avatar" type="file" multiple>
                                                                                </form>
                                                                            </div>
                                                                            <!--end test-->
                                                                        </div>

                                                                        <div class="modal-footer" style="margin-top:0;">

                                                                            <button id="acacel" type="button" class="btn btn-default" data-dismiss="modal">取消</button>

                                                                            <button type="button" class="btn btn-primary" onclick="modifyavatar()">提交更改</button>

                                                                        </div>

                                                                    </div>
                                                                    <!-- /.modal-content -->

                                                                </div>
                                                                <!-- /.modal -->

                                                            </div>



                                                            <div class="col-sm-6" style="margin-top:100px;">

                                                                <input type="text" class="form-control" id="username">

                                                                <span class="help-block">真实姓名能让大家更容易记住你</span>

                                                            </div>

                                            </div>

                                        </form>

                                    </div>



                                    <div>

                                        <form role="form" class="col-sm-offset-1 col-sm-7">

                                            <div class="form-group">

                                                <label for="usr">邮箱地址:</label>

                                                <input type="email" class="form-control" id="email">

                                                <span class="help-block">用于接收通知<span>

								</div>

								<div class="form-group">

									<label>位置:</label>

									<input type="text" class="form-control" id="local">

									<span class="help-block">你在哪儿？</span>

                                            </div>

                                            <div class="form-group">

                                                <label>网站:</label>

                                                <input type="text" class="form-control" id="blog">

                                                <span class="help-block">还有其他的博客吗？告诉大家呀！</span>

                                            </div>

                                            <div class="form-group">

                                                <label>简介:</label>

                                                <textarea class="form-control" rows="5" id="description"></textarea>

                                                <span class="help-block">介绍下你自己吧！不过不要太长哦！</span>

                                            </div>

                                            <div class="col-sm-offset-11" style="margin-top:2%;">

                                                <button type="button" class="btn btn-primary" onclick="modifyuser();">修改信息</button>

                                            </div>



                                            <hr/>

                                        </form>

                                    </div>



                                    <div>



                                        <form role="form" class="col-sm-offset-1 col-sm-7">

                                            <div class="form-group has-warning has-feedback">

                                                <label for="inputWarning2">原密码:</label>

                                                <input type="password" class="form-control" id="pwd">

                                                <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>

                                            </div>

                                            <div class="form-group has-warning has-feedback">

                                                <label for="inputWarning2">新密码:</label>

                                                <input type="password" class="form-control" id="npwd">

                                                <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>

                                            </div>

                                            <div class="form-group has-warning has-feedback">

                                                <label for="inputWarning2">再次输入新密码:</label>

                                                <input type="password" class="form-control" id="cnpwd">

                                                <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>

                                            </div>

                                            <div class="col-sm-offset-11" style="margin-top:5%;">

                                                <button type="button" class="btn btn-danger" onclick="modifypwd()">修改密码</button>

                                            </div>



                                        </form>

                                    </div>



                                </main>



                            </div>

                        </div>

                    </section>

    </div>

    <footer class="site-footer clearfix" style="margin-top:0px;">

        <section class="copyright">
            <a href="/" style="margin-bottom:0px;">
                <%=global.name%>
            </a> © 2016</section>
    </footer>

    <script>
        var menu = new Menu;


        $('#file-avatar').fileinput({

            uploadUrl: '/api/upload/user',
            allowedFileExtensions: ['jpg', 'png', 'gif'],
            maxFileCount: 1,
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
        });

        $('#file-coverplan').fileinput({

            uploadUrl: '/api/upload/user',
            allowedFileExtensions: ['jpg', 'png', 'gif'],
            maxFileCount: 1,
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
        });

        $(function() {

            var coverplan = "<%=user.coverplan%>";

            var username = "<%=user.nickname%>";

            var email = "<%=user.email%>";

            var local = "<%=user.local%>";

            var otherblog = "<%=user.otherblog%>";

            var description = "<%=user.description%>";


            $('#coverplan').css("background-image", coverplan);

            $('#username').val(username);

            $('#email').val(email);

            $('#local').val(local);

            $('#blog').val(otherblog);

            $('#description').val(description);



        });



        function modifyuser() {

            var username = $('#username').val();

            var email = $('#email').val();

            var local = $('#local').val();

            var blog = $('#blog').val();

            var description = $('#description').val();


            console.log(blog);
            $.ajax({

                type: "POST",

                cache: false,

                url: "/api/user/modifyuser",

                data: {

                    username: username,

                    email: email,

                    local: local,

                    blog: blog,

                    description: description

                },

                success: function(msg) {

                    if (msg.status == 0) {

                        alert("修改信息成功！");

                    }

                }

            });



        }



        function modifypwd() {

            var pwd = $('#pwd').val();

            var npwd = $('#npwd').val();

            var cnpwd = $('#cnpwd').val();



            if (pwd != '' && npwd != '' && cnpwd != '') {

                if (npwd == cnpwd) {

                    $.ajax({

                        type: "POST",

                        cache: false,

                        url: "/api/user/changepwd",

                        data: {

                            oldpwd: pwd,

                            newpwd: npwd

                        },

                        success: function(msg) {

                            if (msg.status == 0) {

                                alert("修改密码成功！");
                                location.href = "/";
                            }

                        }

                    });

                } else {

                    alert("两次输入的密码不一致！");

                }

            } else {

                alert("请输入密码信息！");

            }

        }



        function modifyavatar() {

            var avatar = $('#avatarin').val();


            if (avatar != '') {
                $.ajax({

                    type: "POST",

                    cache: false,

                    url: "/api/user/modifyavatar",

                    data: {

                        avatar: avatar

                    },

                    success: function(msg) {

                        if (msg.status == 0) {

                            alert("修改头像成功！");
                            $('#acacel').click();
                            $('#avatar').attr('src', avatar);

                        }

                    }

                });
            }
            $('#acacel').click();
        }

        function modifycoverplan() {

            var coverplan = $('#coverplanin').val();


            if (coverplan != '') {
                $.ajax({

                    type: "POST",

                    cache: false,

                    url: "/api/user/modifycoverplan",

                    data: {

                        coverplan: coverplan

                    },

                    success: function(msg) {

                        if (msg.status == 0) {

                            alert("修改封面背景图片成功！");
                            $('#ccacel').click();
                            $('#coverplan').css("background-image", coverplan);

                        }

                    }

                });
            }

            $('#ccacel').click();

        }
    </script>